// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem530.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @lc app=leetcode.cn id=530 lang=cpp
 *
 * [530] 二叉搜索树的最小绝对差
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void getMinimumDifference(TreeNode* root,vector<int> &res)
    {
        if(root == NULL)
            return;
        getMinimumDifference(root->left,res);
        res.push_back(root->val);
        getMinimumDifference(root->right,res);
        return ;
    }

    int getMinimumDifference(TreeNode* root) {
        vector<int> res;
        getMinimumDifference(root,res);
        int temp = 0;
        int min = INT_MAX;
        for(auto i = 0;i<res.size() - 1;i++)
        {
            temp = res[i+1] - res[i];
            if(temp <= min)
                min = temp;
        }
        return min;
    }
};
// @lc code=end

